<?php
class ControllerCommonHome extends Controller {
	public function index() {
		// load model
		$this->load->language('common/header');
		$data["text_quang_cao"]	 = $this->language->get("text_quang_cao");
		$data["text_video"]		 = $this->language->get("text_video");
		$data['text_home']          = $this->language->get('text_home');
		$data['text_news']          = $this->language->get('text_news');
		$data['text_product']       = $this->language->get('text_product');
		$data['text_aboutus']       = $this->language->get('text_aboutus');
		$data['text_tu_van']        = $this->language->get('text_tu_van');
		$data['text_contact']       = $this->language->get('text_contact');
		$data['text_cart']       	  = $this->language->get('text_cart');
		$data["text_seemore"]	   = $this->language->get('text_seemore');
		
		$this->load->model('simple_blog/article');
		$this->load->model('tool/image');
		
		
		$this->document->setTitle($this->config->get('config_meta_title'));
		$this->document->setDescription($this->config->get('config_meta_description'));
		$this->document->setKeywords($this->config->get('config_meta_keyword'));

		if (isset($this->request->get['route'])) {
			$this->document->addLink(HTTP_SERVER, 'canonical');
		}
		$data["menu_tuvan"] 	= $this->url->link("simple_blog/category&simple_blog_category_id=3");
		$data['column_left'] 	= $this->load->controller('common/column_left');
		$data['column_right'] 	= $this->load->controller('common/column_right');
		$data['content_top'] 	= $this->load->controller('common/content_top');
		$data['content_bottom'] = $this->load->controller('common/content_bottom');
		$data['footer'] 		= $this->load->controller('common/footer');
		$data['header'] 		= $this->load->controller('common/header');
		
		$news	= $this->model_simple_blog_article->getArticlesCategory(array("start"=>0,"limit"=>4,"category"=>2));
		$data['news'] = array();
	 	foreach($news as $article){
			$data['news'][] = array(
				'simple_blog_article_id'		=> $article['simple_blog_article_id'],
				'article_title'				=> $article['article_title'],
				'simple_blog_author_id'		=> $article['simple_blog_author_id'],
				'image'						=> $this->model_tool_image->resize($article['featured_image'],200,150),
				'description'				=> $article['description'],
				'author_name'				=> $article['author_name'],
				'date_added'				=> date('d/m/Y', strtotime($article['date_added'])),
				'date_modified'				=> date('F jS, Y', strtotime($article['date_modified'])),
				'article_href'     			=> $this->url->link('simple_blog/article/view', 'simple_blog_article_id=' . $article['simple_blog_article_id'], 'SSL'),
				'author_href'       		=> $this->url->link('simple_blog/author', 'simple_blog_author_id=' . $article['simple_blog_author_id'], 'SSL')
			);
		}
		$advisory	= $this->model_simple_blog_article->getArticlesCategory(array("start"=>0,"limit"=>10,"category"=>3));
		$data['advisory'] = array();
	 	foreach($advisory as $article){
			$data['advisory'][] = array(
				'simple_blog_article_id'		=> $article['simple_blog_article_id'],
				'article_title'				=> $article['article_title'],
				'simple_blog_author_id'		=> $article['simple_blog_author_id'],
				'image'						=> $this->model_tool_image->resize($article['featured_image'],200,150),
				'description'				=> $article['description'],
				'author_name'				=> $article['author_name'],
				'date_added'				=> date('d/m/Y', strtotime($article['date_added'])),
				'date_modified'				=> date('F jS, Y', strtotime($article['date_modified'])),
				'article_href'     			=> $this->url->link('simple_blog/article/view', 'simple_blog_article_id=' . $article['simple_blog_article_id'], 'SSL'),
				'author_href'       		=> $this->url->link('simple_blog/author', 'simple_blog_author_id=' . $article['simple_blog_author_id'], 'SSL')
			);
		}
		//echo '<pre>';print_r($data['advisory']);exit;
		$videos	= $this->model_simple_blog_article->getArticlesCategory(array("start"=>0,"limit"=>4,"category"=>1));
		$data['videos'] = array();
		if($videos)foreach($videos as $article) {
			$data['videos'][] = array(
				'simple_blog_article_id'	=> $article['simple_blog_article_id'],
				'article_title'				=> $article['article_title'],
				'simple_blog_author_id'		=> $article['simple_blog_author_id'],
				'image'						=> $this->model_tool_image->resize($article['featured_image'],200,150),
				'description'				=> $article['description'],
				'author_name'				=> $article['author_name'],
				'date_added'				=> date('F jS, Y', strtotime($article['date_added'])),
				'date_modified'				=> date('F jS, Y', strtotime($article['date_modified'])),
				'article_href'     			=> $this->url->link('simple_blog/article/view', 'simple_blog_article_id=' . $article['simple_blog_article_id'], 'SSL'),
				'author_href'       		=> $this->url->link('simple_blog/author', 'simple_blog_author_id=' . $article['simple_blog_author_id'], 'SSL')
			);
		}
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/home.tpl')) {
			$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/common/home.tpl', $data));
		} else {
			$this->response->setOutput($this->load->view('default/template/common/home.tpl', $data));
		}
	}
}